package com.com01迭代器模式.test;

public class IteratorBookImpl implements Iterator{
    private BookListImpl bookList = null;
    private int index = 0;
    public IteratorBookImpl(BookListImpl bookList) {
        this.bookList = bookList;
    }

    @Override
    public boolean hasNext() {
        if (index < bookList.getLength()) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Book next() {
        // 返回的其实是当前元素，并且指向下一个 元素
      Book book =   bookList.getElement(index);
        index++;
        return book;
    }
}
